{-# OPTIONS -Wall #-}


--------------------------------------------------------------------------------
-- |
-- Module      :  ZCSV.Utils
-- Copyright   :  (c) Stephen Tetley 2014
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Lexer monad.
-- 
--------------------------------------------------------------------------------

module ZCSV.Utils
  ( 

    trimR
  , trimL
  , trimLR

  , H
  , emptyH
  , wrapH
  , snocH
  , toListH
  
  ) where

import Data.Char

trimL :: String -> String
trimL = step 
  where
    step []                 = []
    step (a:as) | isSpace a = step as
                | otherwise = a:as 

trimR :: String -> String
trimR = foldr fn []
  where
    fn a [] | isSpace a = []
    fn a ac             = a:ac

trimLR :: String -> String
trimLR = trimR . trimL 

--------------------------------------------------------------------------------
-- Hughes lists


type H a = [a] -> [a]

emptyH :: H a
emptyH = id

wrapH :: a -> H a
wrapH c = (c:)

snocH :: H a -> a -> H a
snocH h c = h . (c:)

toListH :: H a -> [a]
toListH = ($ [])
